angular.module('service', [])
.factory('ls', ['$window', function($window) {  
   return {  
     set: function(key, value) {  
      $window.localStorage[key] = value;  
    },  
    get: function(key, defaultValue) {  
       return $window.localStorage[key] || defaultValue;  
     },  
     setObject: function(key, value) {  
       $window.localStorage[key] = JSON.stringify(value);  
     },  
     getObject: function(key) {  
       return JSON.parse($window.localStorage[key] || '{}');  
     }  
   }  
 }])
.constant('weburl', 'http://10.66.20.33:9080/realty')
.service('LoginService', function($http, $log,weburl,ls) {
    this.getData = function(data) {
      ls.set("username",data.username);
      var res = $http({
        method: 'GET',
        url: weburl+"/ajaxUser.do?method=LoginForMobile&ect="+Math.random(),
        params:{  
                'username': data.username,
                'password': data.password 
            }  
      }).success(function(data) {
        $log.log(data); 
      });

      return res;
    };
  }).service('WorkflowService', function($http, $log,weburl,ls) {
    this.getData = function(data) {
      var res = $http({
        method: 'GET',
        url: weburl+"/ajaxSnaker.do?method=WorkList&ect="+Math.random(),
        params:{  
                'token': ls.get('token'),
            }  
      }).success(function(data) {
        $log.log(data); 
      });

      return res;
    };
  }).service('ApproveService', function($http, $log,weburl,ls) {
    this.approve = function(data) {
      var res = $http({
        method: 'GET',
        url: weburl+"/ajaxRentContract.do?method=CheckInfo&ect="+Math.random(),
        params:{  
                'token': ls.get('token'),
                'id':data.id,
                'reply':data.reply,
                'answer':data.answer,
                'isto':data.isto
            }  
      }).success(function(data) {
        $log.log(data); 
      });

      return res;
    };
  }).service('SearchService', function($http, $log,weburl,ls) {
    this.getData = function(id) {
      var res = $http({
        method: 'GET',
        url: weburl+"/ajaxRentContract.do?method=GetInfo&id="+id+"&ect="+Math.random(),
        params:{  
                'token': ls.get('token'),
            }  
      }).success(function(data) {
        $log.log(data); 
      });

      return res;
    };
  })